package com.ultrawise.survey.module.surevybase.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ultrawise.survey.core.Page;
import com.ultrawise.survey.core.base.BaseService;
import com.ultrawise.survey.core.base.ServiceException;
import com.ultrawise.survey.module.surevybase.dao.TSurveyDataTotalDAO;
import com.ultrawise.survey.module.surevybase.vo.TSurveyDataTotal;
import com.ultrawise.survey.module.user.vo.TSurveyInfoUsers;

@Service("tSurveyDataTotalService")
public class TSurveyDataTotalService extends BaseService {
	@Autowired
	TSurveyDataTotalDAO tSurveyDataTotalDAO;

	public Integer queryPersonnum(String syid) {
		String sql = "select count(*) as num from t_survey_obj"+syid+" ";//动态表编号
		Integer numperson = tSurveyDataTotalDAO.getJdbcTemplate().queryForInt(sql);
		return numperson;
	}
	
	
//使用SQL创建一个动态字段的表
	public List<Map<String,Object>> queryinfo(String syid,String qnid) {
		String sql = "select b.QN_NAME,US_ID,AS_OTHER,c.*  from t_survey_data_answer a " +
				"LEFT JOIN t_survey_info_question b ON b.ID=a.QN_ID " +
				"LEFT JOIN t_survey_obj"+syid+" c ON c.ID=a.US_ID " +
				"where a.qn_id="+qnid+" and b.QN_TYPE=2 or b.QN_TYPE=4 or b.QN_TYPE=5" ;
				List<Map<String,Object>> numinfo = tSurveyDataTotalDAO.queryBysql(sql);
		return numinfo;
	}
	
	
	/*****
	 * 统计出某个问卷的具体的问题所选择的答案有什么，并且具体选择的人数几人。
	 * @param dto
	 * @param pageNo
	 * @param pageSize
	 * @return
	 * @throws ServiceException
	 */
	public Page<TSurveyDataTotal> queryTotal(TSurveyDataTotal dto, int pageNo, int pageSize) throws ServiceException {
		Page<TSurveyDataTotal> page = null;
		try {
			page = tSurveyDataTotalDAO.getTsurveTotalpage(dto, pageNo, pageSize);
		} catch (Exception e) {
			throw new ServiceException("查询失败", e);
		}
		return page;
	}

}
